package com.mti.monitor.rst;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class Result<T> {
    private int code;
    private String message;
    private T data;

    public Result(int code, String message) {
        this.code = code;
        this.message = message;

    }

    public static <T> Result<T> ok(T data) {
        return new Result<>(200, "OK", data);
    }

    public static <T> Result<T> fail(int code, String msg) {
        return new Result<>(code, msg);
    }

    public static <T> Result<T> ok() {
        return new Result<>(200, "OK");
    }

    // 失败情况的静态构造方法，可以传入自定义的错误码和消息
    public static <T> Result<T> error(int code, String message) {
        return new Result<>(code, message, null);
    }
}
